<?php

use Drupal\distribution\Entity\Distribution;

/**
 * Implements hook_rules_action_info().
 */
function shusy_distribution_rules_action_info() {
  return [
    'shusy_distribution_rules_action_set_team' => [
      'label' => t('设置团长'),
      'parameter' => [
        'account' => [
          'type' => 'user',
          'label' => t('用户'),
        ],
      ],
      'group' => t('shusy_distribution'),
    ],
  ];
}

function shusy_distribution_rules_action_set_team($account) {
  $uid = $account->uid;
  $team = Distribution::getDistribution($uid);
  if ($team instanceof Distribution) {
    $team->tid = $uid;
    $team->save();
  }
}
